<template>
  <div>
      <h2>库存统计</h2>
      <div class="chart" id="chartFour">
          图表的容器
      </div>
  </div>
</template>

<script>
import {inject,onMounted,reactive} from "vue"
export default {
  setup(){
    let data = reactive({})
    let $echarts = inject("echarts")
    let $http = inject("axios")

    onMounted(()=>{
      getState().then(()=>{
        let myChart = $echarts.init(document.getElementById("chartFour"))
        myChart.setOption({
          grid: {
            left: "1%",
            right: "4%",
            bottom: "3%",
            containLabel: true
          },
          xAxis: {
            type: "category",
            data: data.data.chartData.chartData.day,
            axisLine: {
              lineStyle: {
                color: "#fff"
              }
            }
          },
          yAxis: {
            type: "value",
            axisLine: {
              lineStyle: {
                color: "#fff"
              }
            }
          },
          legend: {},
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow"
            }
          },
          series: [
            {
              name: "服饰",
              type: "bar",
              data: data.data.chartData.chartData.num.Clothes,
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "数码",
              type: "bar",
              data: data.data.chartData.chartData.num.digit,
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "家电",
              type: "bar",
              data: data.data.chartData.chartData.num.Electrical,
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "家居",
              type: "bar",
              data: data.data.chartData.chartData.num.gear,
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            },
            {
              name: "日化",
              type: "bar",
              data: data.data.chartData.chartData.num.Chemicals,
              stack: "Total",
              label: {
                show: true
              },
              emphasis: {
                focus: "series"
              }
            }
          ]
        })
      })
    })

    async function getState(){
      data = await $http({url: "/four/data",method: "get"})
      console.log("four",data)
    }

    return{
      data,
      getState
    }
  }
}
</script>

<style>
.chart{
  height: 4.5rem;
}
h2 {
  height: 0.6rem;
  color: #fff;
  line-height: 0.6rem;
  font-size: 0.25rem;
  text-align: center;
}
</style>